﻿<?php

//downErWeiMa($_GET['starTime'],$_GET['endTime'],$_GET['shengFeng']);

ini_set("display_errors", "On");

downExcelAll();

function downExcelAll(){


	$qure = "SELECT title,start_date,NAME,link_url FROM youjutell WHERE NAME IN ".$_GET['ABku']." AND start_date BETWEEN '".$_GET['starDate']."' AND '".$_GET['endDate']."'";

	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);
	$arr=mysqli_fetch_all($result, 1);

	// echo '<pre>';

	// 	var_dump($arr);

	// echo '</pre>';


	

	require_once 'C:\phpstudy_pro\WWW\cscs.qumei.com\weizanZB\PHPExcel-1.8\Classes\PHPExcel.php';

	

	$excelFiled=array("日期","渠道","客户名称","联系方式");

	//var_dump($excelFiled);

	$row=1;

	$objPHPExcel=new PHPExcel();

	$objPHPExcel->getActiveSheet()->fromArray($excelFiled,'A1');

	for($i=0;$i<count($arr);$i++){

		//$disCity=$arr['tell'][$i];

	 	$row+=1;

	 	

	 	$objPHPExcel->getActiveSheet()->setCellValue('A'.$row,$arr[$i]['start_date']);

	 	if($arr[$i]['NAME'] == '591-lx'){

	 		$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,'A');
	 		$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $arr[$i]['title'].'_A');

	 	}else{

	 		$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,'B');
	 		$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $arr[$i]['title'].'_B');
	 	}

	 	
	 	$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $arr[$i]['link_url']);


	}

		$objWriter =PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');

		$nameFile='电话导入模板'.date("Ymd");

		// echo __DIR__."\\excel\\".$nameFile.".xlsx";

		$objWriter->save(__DIR__."\\excel\\".$nameFile.".xlsx");  // //excel/二维码.xlsx

		// header("Location: excel\\".$nameFile.".xlsx");

		echo "excel\\".$nameFile.".xlsx";

}

?>